﻿using System;
using System.Collections.Generic;
using ZX.Web.UI.Controls;
using ZX.BLL.Extend;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using System.Data;
namespace ZX.WebApp.Crm.Report
{
    public partial class RptCustomerInfo : BasePage
    {
        BCrmReport BReport = new BCrmReport();
        BTCrmCustomer bll = new BTCrmCustomer();
        string strNoData = "";
        public string fcid = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            fcid = Request.QueryString["functionID"] == null ? "" : Request.QueryString["functionID"];
            string type = Request.QueryString["type"] == null ? "" : Request.QueryString["type"];
            string Id = Request.QueryString["id"] == null ? "" : Request.QueryString["id"];
            DoReport(Id,type);
               
        }
        private void DoReport(string  Id,string  type)
        {
            try
            {
                DataSet myDataSet = new DataSet();
                myDataSet.DataSetName = "DsCrmCustomerInfo";
                BaseBussnies deptUserPost = new BaseBussnies();
                deptUserPost.entity = new V_DatUserPostDept();
                DataTable TypeDataTable = new DataTable();
                DataTable TradeDataTable = new DataTable();
                DataTable ProductDataTable = new DataTable();
                DataTable PersonDataTable = new DataTable();
                if (type.Trim().Length == 0)
                {
                    IList<V_DatUserPostDept> IDatUserPostDept = deptUserPost.GetEntitys<V_DatUserPostDept>(" UseriD='" + this.UserId.ToString() + "'");
                    if (IDatUserPostDept != null)
                    {

                        TypeDataTable = BReport.ReturnTableTypeNameDeptID(IDatUserPostDept[0].DeptID,1);
                        TradeDataTable = BReport.ReturnTableTradeNameDeptID(IDatUserPostDept[0].DeptID);
                        ProductDataTable = BReport.ReturnTableProductNameDeptID(IDatUserPostDept[0].DeptID);
                        PersonDataTable = BReport.ReturnTablePersonNameDeptID(IDatUserPostDept[0].DeptID);
                    }
                    else
                    {
                        TypeDataTable = BReport.ReturnTableTypeName(new Guid(this.UserId.ToString()),1);
                        TradeDataTable = BReport.ReturnTableTradeName(new Guid(this.UserId.ToString()));
                        ProductDataTable = BReport.ReturnProductName(new Guid(this.UserId.ToString()));
                        PersonDataTable = BReport.ReturnPersonName(new Guid(this.UserId.ToString()));
                    }
                }
                else if (type.Trim() == "1")
                {
                    TypeDataTable = BReport.ReturnTableTypeNameDeptID(new Guid(Id == "" ? Guid.Empty.ToString() : Id),1);
                    TradeDataTable = BReport.ReturnTableTradeNameDeptID(new Guid(Id==""?Guid.Empty.ToString():Id));
                    ProductDataTable = BReport.ReturnTableProductNameDeptID(new Guid(Id == "" ? Guid.Empty.ToString() : Id));
                    PersonDataTable = BReport.ReturnTablePersonNameDeptID(new Guid(Id == "" ? Guid.Empty.ToString() : Id));
                }
                else if (type.Trim() == "2")
                {
                    TypeDataTable = BReport.ReturnTableTypeName(new Guid(Id),1);
                    TradeDataTable = BReport.ReturnTableTradeName(new Guid(Id));
                    ProductDataTable = BReport.ReturnProductName(new Guid(Id));
                    PersonDataTable = BReport.ReturnPersonName(new Guid(Id));
                }
                TypeDataTable.TableName = "DsTypeName";
                TradeDataTable.TableName = "DsTradeName";
                ProductDataTable.TableName = "DsProductName";
                PersonDataTable.TableName = "DsPersonName";
                myDataSet.Tables.Add(TypeDataTable.Copy());
                myDataSet.Tables.Add(TradeDataTable.Copy());
                myDataSet.Tables.Add(ProductDataTable.Copy());
                myDataSet.Tables.Add(PersonDataTable.Copy());
                ZX.CRM.Report.CrmReport.RptCustomerInfo crm = new ZX.CRM.Report.CrmReport.RptCustomerInfo();
                crm.DataSource = myDataSet;
                RV.Report = crm;
            }
            catch
            { 
            }
              
            
           //}
        }
    }
}